classdef SecondaryPRNCode < PRNCode

properties (SetAccess = protected)
	MatlabSavedCodesFileName;
end % end of properties

methods
	
	function obj = SecondaryPRNCode(Name)
		obj = obj@PRNCode(Name);

		switch (obj.Name)
			case 'E5aI'
				obj.CodesFileName = './E5aI_secondary_codes.txt';
				obj.MatlabSavedCodesFileName = './E5aI_secondary_codes.mat';
				obj.NumberOfChips = 20;
				obj.ChipPeriod = 1e-3;
			case 'E5aQ'
				obj.CodesFileName = './E5aQ_secondary_codes.txt';
				obj.MatlabSavedCodesFileName = './E5aQ_secondary_codes.mat';
				obj.NumberOfChips = 100;
				obj.ChipPeriod = 1e-3;
			case 'E5bI'
				obj.CodesFileName = './E5bI_secondary_codes.txt';
				obj.MatlabSavedCodesFileName = './E5bI_secondary_codes.mat';
				obj.NumberOfChips = 4;
				obj.ChipPeriod = 1e-3;
			case 'E5bQ'
				obj.CodesFileName = './E5bQ_secondary_codes.txt';
				obj.MatlabSavedCodesFileName = './E5bQ_secondary_codes.mat';
				obj.NumberOfChips = 100;
				obj.ChipPeriod = 1e-3;
			case 'E1c'
				obj.CodesFileName = './E1c_secondary_codes.txt';
				obj.MatlabSavedCodesFileName = './E1c_secondary_codes.mat';
				obj.NumberOfChips = 25;
				obj.ChipPeriod = 4e-3;
			case 'B1'
				obj.CodesFileName = './B1_secondary_codes.txt';
				obj.MatlabSavedCodesFileName = './B1_secondary_codes.mat';
				obj.NumberOfChips = 20;
				obj.ChipPeriod = 1e-3;
			otherwise
				error('Unknown signal name');
		end
		
		try 
			load(obj.MatlabSavedCodesFileName, 'Codes');
			obj.Codes = Codes;
		catch exception
			obj.loadCodes();
			Codes = obj.Codes;
			save(obj.MatlabSavedCodesFileName, 'Codes');
		end

	end
	
	function out = getCode(obj, SVID, TimeShift)
		TimeShift = mod(TimeShift, obj.NumberOfChips);
		if (TimeShift < 0)
			TimeShift = obj.NumberOfChips - TimeShift;
		end
		out = circshift(obj.Codes(SVID, :).', TimeShift).';
	end

end % end of methods

end % end of class
